package com.teame.readbaby;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.EditText;
import android.widget.FrameLayout;
import android.widget.ListView;

import com.teame.readbaby.parser.SearchKeywordsParser;
import com.teame.readbaby.util.ConstantValue;
import com.teame.readbaby.vo.ProductKeyWordsInfo;


public class SearchActivity extends BaseActivity {
	private EditText keyWordEdit;//搜索输入文本框：
	private FrameLayout fraSearch;//搜索界面的搜索框：
	private ListView hotWordsLv;//搜索热门和历史列表项：
	
	private List<ProductKeyWordsInfo> keyWordsList = new ArrayList<ProductKeyWordsInfo>();
	

	@Override
	protected void findViewById() {
		keyWordEdit = (EditText) findViewById(R.id.keyWordEdit);
		fraSearch = (FrameLayout) findViewById(R.id.fraSearch);
		hotWordsLv = (ListView) findViewById(R.id.hotWordsLv);
	}

	/**
	 * 加载布局文件：
	 */
	@Override
	protected void loadViewLayout() {
		setContentView(R.layout.search_activity);
	}

	/**
	 * 向本地请求数据，获取json数据：
	 */
	@Override
	protected void processLogic() {
		// 1.请求的url地址：
				String url = ConstantValue.HOST + ConstantValue.DETAILEADDRESS;
				// 2.请求的参数，没有为null：
				Map<String, String> params = new HashMap<String, String>();
				params.put("keyword", "");
				params.put("page", "");
				params.put("pageNum", "");
				params.put("orderby", "");
				// 3.json数据解析器，大家需要按照自己获取的json的结构自己编写，要继承basePaser
				// 4.回调函数：
				getDataFromServer(url, null, new SearchKeywordsParser(),
						new DataCallback<List<ProductKeyWordsInfo>>() {

							@Override
							public void processData(List<ProductKeyWordsInfo> paramObject,
									boolean paramBoolean) {
								if (!paramBoolean || paramObject == null) {// 获取失败

								} else {// 获取成功
									
									// for (HomeClassifyInfo info : paramObject) {
									// Logger.i(TAG, info.toString());
									// }
								}
							}
						});
				getDataFromServer(url, null, new SearchKeywordsParser(),
						new DataCallback<List<ProductKeyWordsInfo>>() {
					
					@Override
					public void processData(List<ProductKeyWordsInfo> paramObject,
							boolean paramBoolean) {
						if (!paramBoolean || paramObject == null) {// 获取失败
							
						} else {// 获取成功
							
							// for (HomeClassifyInfo info : paramObject) {
							// Logger.i(TAG, info.toString());
							// }
						}
					}
				});
				
				hotWordsLv.setAdapter(new HotWordsListAdapter(this));

	}
	
	/**
	 * 搜索列表适配器：
	 * @author Administrator
	 *
	 */
	private class HotWordsListAdapter extends BaseAdapter{

		private Context context;

		public HotWordsListAdapter(Context context) {
			this.context = context;
		}
		
		@Override
		public int getCount() {
			// TODO Auto-generated method stub
			return 0;
		}

		@Override
		public Object getItem(int position) {
			// TODO Auto-generated method stub
			return null;
		}

		@Override
		public long getItemId(int position) {
			// TODO Auto-generated method stub
			return 0;
		}

		@Override
		public View getView(int position, View convertView, ViewGroup parent) {
			View view = View.inflate(context, R.layout.search_item, null);
			return null;
		}
		
	}
	
	
	/**
	 * 搜索结果列表项适配器
	 * @author Administrator
	 *
	 */
	private class SearchResultListAdapter extends BaseAdapter{

		@Override
		public int getCount() {
			// TODO Auto-generated method stub
			return 0;
		}

		@Override
		public Object getItem(int position) {
			// TODO Auto-generated method stub
			return null;
		}

		@Override
		public long getItemId(int position) {
			// TODO Auto-generated method stub
			return 0;
		}

		@Override
		public View getView(int position, View convertView, ViewGroup parent) {
			// TODO Auto-generated method stub
			return null;
		}
		
	}

	
	@Override
	protected void setListener() {
		fraSearch.setOnClickListener(this);

	}

	@Override
	protected void onClickEvent(View paramView) {
		// TODO Auto-generated method stub
		
	}

}
